package com.vue.controller;


import com.alibaba.fastjson.JSON;
import com.vue.bean.R;
import com.vue.entity.DishesMenuEntity;
import com.vue.service.IDishesMenuService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜单菜品表 前端控制器
 * </p>
 *
 * @author wangruijie
 * @since 2024-08-04
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/dishesMenu")
public class DishesMenuController {

    private IDishesMenuService dishesMenuService;

    @GetMapping("/selectList")
    public R selectList(DishesMenuEntity po){
        log.info("查询列表：{}", JSON.toJSON(po));
        try {
            List<DishesMenuEntity> list = dishesMenuService.selectList(po);
            return R.data(list);
        } catch (Exception e) {
            return R.fail("暂无数据");
        }
    }

    @GetMapping("/selectById")
    public R selectById(@RequestParam("id") Long id){
        log.info("查询菜品菜单详情：{}", id);
        try {
            return dishesMenuService.selectById(id);
        } catch (Exception e) {
            return R.fail("查询菜品菜单详情异常");
        }
    }

    @PostMapping("/addOrEditDishesMenu")
    public R addDishesMenu(@RequestBody DishesMenuEntity po){
        log.info("新增菜品菜单：{}", JSON.toJSON(po));
        try {
            return dishesMenuService.addOrEditDishesMenu(po);
        } catch (Exception e) {
            return R.fail("新增异常");
        }
    }

    @GetMapping("/deleteById")
    public R deleteById(@RequestParam("id") Long id){
        log.info("删除菜品菜单：{}", id);
        try {
            return dishesMenuService.deleteById(id);
        } catch (Exception e) {
            return R.fail("新增异常");
        }
    }
}
